﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.Trading.Purchase.GoodsPurchaseCertificate;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.Trading.Purchase.GoodsPurchaseCertificate;

namespace BCTMSRESTful.Controllers.Management.Trading.Purchase
{
    /// <summary>
    /// 商品采购单记账凭证
    /// </summary>
    [ApiExplorerSettings(GroupName = "AdminTrading")]
    [Route("api/v1/sim/[controller]")]
    public class GoodsPurchaseCertificateController : ManagementBaseController
    {
        private readonly IGoodsPurchaseCertificateService goodsPurchaseCertificateService;

        public GoodsPurchaseCertificateController(IGoodsPurchaseCertificateService goodsPurchaseCertificateService)
        {
            this.goodsPurchaseCertificateService = goodsPurchaseCertificateService;
        }

        #region 添加商品采购单记账凭证
        /// <summary>
        ///  添加商品采购单记账凭证
        /// </summary>
        /// <param name="requestDto">商品采购单记账凭证信息</param>
        /// <response code="201">添加商品采购单记账凭证成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加商品采购单记账凭证")]
        [ProducesResponseType(typeof(GoodsPurchaseCertificateDto), 201)]
        public IActionResult Post(
            [FromBody]GoodsPurchaseCertificateRequestDto requestDto)
        {
            var result = this.goodsPurchaseCertificateService.Add(requestDto,this.Admin);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改商品采购单记账凭证
        /// <summary>
        ///  修改商品采购单记账凭证
        /// </summary>
        /// <param name="goodsPurchaseCertificateId">商品采购单记账凭证Id</param>
        /// <param name="requestDto">商品采购单记账凭证信息</param>
        /// <response code="200">修改商品采购单记账凭证成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{goods_purchase_certificate_id}")]
        [Log("修改商品采购单记账凭证")]
        [ProducesResponseType(typeof(GoodsPurchaseCertificateDto), 200)]
        public IActionResult Put([FromRoute(Name = "goods_purchase_certificate_id")]long goodsPurchaseCertificateId, [FromBody]GoodsPurchaseCertificateRequestDto requestDto)
        {
            GoodsPurchaseCertificatePutDto putDto = requestDto.As<GoodsPurchaseCertificatePutDto>();
            putDto.GoodsPurchaseCertificateId = goodsPurchaseCertificateId;
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseCertificateService.Update(putDto,this.Admin));
        }
        #endregion

        #region 删除商品采购单记账凭证
        /// <summary>
        ///  删除商品采购单记账凭证
        /// </summary>
        /// <param name="goodsPurchaseCertificateId">商品采购单记账凭证Id</param>
        /// <response code="204">删除商品采购单记账凭证成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{goods_purchase_certificate_id}")]
        [Log("删除商品采购单记账凭证")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "goods_purchase_certificate_id")]long goodsPurchaseCertificateId)
        {
            this.goodsPurchaseCertificateService.Delete(goodsPurchaseCertificateId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取商品采购单记账凭证
        /// <summary>
        ///  获取商品采购单记账凭证
        /// </summary>
        /// <param name="goodsPurchaseCertificateId">商品采购单记账凭证Id</param>
        /// <response code="200">获取商品采购单记账凭证</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{goods_purchase_certificate_id}")]
        [ProducesResponseType(typeof(GoodsPurchaseCertificateDto), 200)]
        public IActionResult Get([FromRoute(Name = "goods_purchase_certificate_id")]long goodsPurchaseCertificateId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseCertificateService.Get(goodsPurchaseCertificateId));
        }
        #endregion

        #region 获取商品采购单记账凭证列表
        /// <summary>
        ///  获取商品采购单记账凭证列表
        /// </summary>
        /// <param name="goodsPurchaseId">商品采购单Id</param>
        /// <response code="200">获取商品采购单记账凭证列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("List/{goods_purchase_id}")]
        [ProducesResponseType(typeof(IEnumerable<GoodsPurchaseCertificateDto>), 200)]
        public IActionResult GetList([FromRoute(Name = "goods_purchase_id")]long goodsPurchaseId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseCertificateService.GetList(goodsPurchaseId));
        }
        #endregion

        #region 获取商品采购单记账凭证（分页）
        /// <summary>
        ///  获取商品采购单记账凭证（分页）
        /// </summary>
        /// <param name="goodsPurchaseId">商品采购单Id</param>
        /// <param name="certificateNo">凭证编号</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取商品采购单记账凭证（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<GoodsPurchaseCertificateDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "goods_purchase_id")]long? goodsPurchaseId,
            [FromQuery(Name = "certificate_no")]string certificateNo,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "sort_name")]string sortName,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseCertificateService.Query(goodsPurchaseId, certificateNo,start, end, sortName, ascending, index, size));
        }
        #endregion
    }
}

